package com.tanhua.admin.controller;

import com.tanhua.model.dto.UserFreeze;
import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManagerController {

    @Autowired
    private ManagerService managerService;


    /**
     * 后台管理,分页查询所有注册用户信息
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity userList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = managerService.findAllUsers(page, pagesize);

        return ResponseEntity.ok(result);
    }

    /**
     * 查询单个用户详情
     */
    @GetMapping("users/{userId}")
    public ResponseEntity findById(@PathVariable("userId") Long id) {
        UserInfo info = managerService.findById(id);
        return ResponseEntity.ok(info);
    }

    /**
     * 查看视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity findVideos(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize,
            Long uid) {
        PageResult result = managerService.findVideos(page, pagesize, uid);
        return ResponseEntity.ok(result);
    }

    //查看id 的所有动态列表
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid, Integer state) {
        PageResult result = managerService.findAllMovements(page, pagesize, uid, state);
        return ResponseEntity.ok(result);
    }

    //用户冻结
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody UserFreeze userFreeze) {
        Map msg =  managerService.userFreeze(userFreeze);
        return ResponseEntity.ok(msg);
    }

    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody  UserFreeze freeze) {
        Map map =  managerService.userUnfreeze(freeze);
        return ResponseEntity.ok(map);
    }

}
